<?php
namespace app\admin\controller;

use think\Db;
use think\Controller;
use think\Request;

class Base extends Controller{

    protected $param;
    protected $isLogin = false;     //登录状态

    public function initialize()
    {
//        $this->request    = Request::instance();
        $this->param      = $this->request->param();
        if (!$this->isLogin()) {
            $this->redirect('login/login');
        }
    }


    public function isLogin()
    {

        if ($this->isLogin) {
            return true;
        }
        $admin = session('uid');
        if (!$admin) {
            return false;
        }
        $this->isLogin = true;
        return true;
    }
//
//    /**
//     * 获取当前请求的Accept头信息
//     * @return string
//     */
//    protected function getAcceptType()
//    {
//        $type = array(
//            'html' => 'text/html,application/xhtml+xml,*/*',
//            'xml' => 'application/xml,text/xml,application/x-xml',
//            'json' => 'application/json,text/x-json,application/jsonrequest,text/json',
//            'js' => 'text/javascript,application/javascript,application/x-javascript',
//            'css' => 'text/css',
//            'rss' => 'application/rss+xml',
//            'yaml' => 'application/x-yaml,text/yaml',
//            'atom' => 'application/atom+xml',
//            'pdf' => 'application/pdf',
//            'text' => 'text/plain',
//            'png' => 'image/png',
//            'jpg' => 'image/jpg,image/jpeg,image/pjpeg',
//            'gif' => 'image/gif',
//            'csv' => 'text/csv'
//        );
//
//        foreach ($type as $key => $val) {
//            $array = explode(',', $val);
//            foreach ($array as $k => $v) {
//                if (stristr($_SERVER['HTTP_ACCEPT'], $v)) {
//                    return $key;
//                }
//            }
//        }
//        return false;
//    }

}